<?php

/*Codigo para notificar los campos vacios*/

if($enviar)
{
if ($usuario=="" && $clave=="") {
    echo "<script>alert('Tiene que completar todos los campos')</script>";
  }
  else
  {
   header("location:redir.php?usuario=$usuario&clave=$clave");
  } 
}

/*Codigo para loguearse con los datos de la base de datos*/

ini_set('display errors','Off');
ini_set('display_startup_errors','Off');
error_reporting(0);

$usuario = $_POST['username'];
$clave = $_POST['clave'];
$sesion_login = true;

    function Conectarse()
    {
        if (!($link=mysql_connect('localhost','root','root'))) {
            echo "Error al conectar con la base de datos";
                exit();
        }
        if (mysql_select_db('usuario',$link)) {
            echo "Error al seleccionar la base de datos";
            exit();
        }
        return $link;
    }

$con = Conectarse();
$query = "SELECT * FROM usuario WHERE Nombre = '".$usuario."' AND clave = ' ".$clave. " ' ";
$q = mysql_query($query,$con);

  try {

  if (mysql_result($q,0)) {
    $result = mysql_result($q, 0);
    echo "Usuario validad correctamente";
  }
  else {
    echo "Usuario o password incorrecto";
  }
    
  } catch (Exception $error){}
  mysql_close($con);

?>
<!DOCTYPE html>
<html lang="es">
  <head>
    <meta charset="utf-8">
    <meta name="viewport" content="width=device-width, initial-scale=1.0">
    <meta name="description" content="">
    <meta name="author" content="">

    <title>Raccoon Sell</title>

    <!-- Bootstrap core CSS -->
    <link href="css/bootstrap.css" rel="stylesheet">

    <!-- Add custom CSS here -->
    <link href="css/small-business.css" rel="stylesheet">

    <!-- Agrega el CSS del formulario -->
    <link rel="stylesheet" type="text/css" href="css/form.css">

  </head>

  <body>

    <nav class="navbar navbar-inverse navbar-fixed-top" role="navigation">
      <div class="container">
        <div class="navbar-header">
          <button type="button" class="navbar-toggle" data-toggle="collapse" data-target=".navbar-ex1-collapse">
            <span class="sr-only">Toggle navigation</span>
            <span class="icon-bar"></span>
            <span class="icon-bar"></span>
            <span class="icon-bar"></span>
          </button>
          <!-- You'll want to use a responsive image option so this logo looks good on devices - I recommend using something like retina.js (do a quick Google search for it and you'll find it) -->
          <a class="navbar-brand logo-nav" href="index.php"><img src="images/logo.png"></a>
        </div>

        <!-- Collect the nav links, forms, and other content for toggling -->
        <div class="collapse navbar-collapse navbar-ex1-collapse">
          <ul class="nav navbar-nav navbar-right">
            <li><a href="#about">Acerca de nosotros</a></li>
            <li><a href="#contact">Contacto</a></li>
          </ul>
        </div><!-- /.navbar-collapse -->
      </div><!-- /.container -->
    </nav>

	<center><h1>Login</h1></center>
	<br>
	<center><img src="images/me-gusta.png" width="175" height="181"></center>
	<br>
	<center>
	<form name="form1">
    <table>
		<tr>
			<td><label>Nombre de usuario:</label><br><input title="Ingrese su nombre de usuario" type="text" name="usuario" required /></td>
		</tr>
		<tr>
			<td><label>Contraseña:</label><br><input title="Ingrese su contraseña" type="text" name="clave" required /></td>
		</tr>
	</table>
		<br>
		<input type="submit" value="Ingresar" name="enviar">
		<input type="reset" value="Borrar">
	</center>
</form>
    <!-- Bootstrap core JavaScript -->
    <!-- Placed at the end of the document so the pages load faster -->
    <!-- Make sure to add jQuery - download the most recent version at http://jquery.com/ -->
    <script src="js/jquery.js"></script>
    <script src="js/bootstrap.js"></script>
	
  </body>
</html>